package com.tyut.service.impl;

import com.tyut.mapper.CustomerMapper;
import com.tyut.pojo.Customer;
import com.tyut.service.CustomerService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户表业务层
 */
@Service
@Transactional
public class CustomerServiceImpl implements CustomerService {
    @Resource
    private CustomerMapper customerMapper;

    /**
     * 增加用户
     * @param customer
     * @return
     */
    public boolean addCustomer(Customer customer) {
        return customerMapper.addCustomer(customer) > 0;
    }

    /**
     * 删除用户
     * @param cid
     */
    public boolean deleteCustomer(Integer cid) {
        return customerMapper.deleteCustomer(cid) > 0;
    }

    /**
     * 修改用户
     * @param customer
     */
    public boolean updateCustomer(Customer customer) {
        return customerMapper.updateCustomer(customer) > 0;
    }

    /**
     * 查询所有用户
     * @return
     */
    public List<Customer> queryListCustomer() {
        List<Customer> customers = customerMapper.queryListCustomer();
        return customers;
    }

    /**
     * 根据用户的id查询用户
     * @param cid
     * @return
     */
    public Customer queryCustomerById(Integer cid) {
        Customer customer = customerMapper.queryCustomerById(cid);
        return customer;
    }

    @Override
    public Customer loginCustomer(Customer customer) {
        return customerMapper.loginCustomer(customer);
    }

}
